﻿/*  CamHelper (See http://camhelper.codeplex.com/ or https://bitbucket.org/AndiKS/camhelper for more Info)
    Copyright (C) 2011 Andreas Wimmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using CamHelper.Interpreter;
using NUnit.Framework;

namespace CamHelper.Tests.Interpreter
{
    [TestFixture]
    public class ScannerTest
    {
        [Test]
        public void OneWord()
        {
            var cmd = "test";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], cmd);
        }

        [Test]
        public void TwoWords()
        {
            var cmd = "test two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "test");
            Assert.AreEqual(cmds[1], " ");
            Assert.AreEqual(cmds[2], "two");
        }

        [Test]
        public void Addition()
        {
            var cmd = "one+two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], "+");
            Assert.AreEqual(cmds[2], "two");
        }

        [Test]
        public void AdditionWhiteSpace()
        {
            var cmd = "one + two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], " ");
            Assert.AreEqual(cmds[2], "+");
            Assert.AreEqual(cmds[3], " ");
            Assert.AreEqual(cmds[4], "two");
        }

        [Test]
        public void Subtraction()
        {
            var cmd = "one-two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], "-");
            Assert.AreEqual(cmds[2], "two");
        }

        [Test]
        public void SubtractionWhiteSpace()
        {
            var cmd = "one - two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], " ");
            Assert.AreEqual(cmds[2], "-");
            Assert.AreEqual(cmds[3], " ");
            Assert.AreEqual(cmds[4], "two");
        }

        [Test]
        public void Multiplication()
        {
            var cmd = "one*two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], "*");
            Assert.AreEqual(cmds[2], "two");
        }

        [Test]
        public void MultiplicationWhiteSpace()
        {
            var cmd = "one * two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], " ");
            Assert.AreEqual(cmds[2], "*");
            Assert.AreEqual(cmds[3], " ");
            Assert.AreEqual(cmds[4], "two");
        }

        [Test]
        public void Division()
        {
            var cmd = "one/two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], "/");
            Assert.AreEqual(cmds[2], "two");
        }

        [Test]
        public void DivisionWhiteSpace()
        {
            var cmd = "one / two";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "one");
            Assert.AreEqual(cmds[1], " ");
            Assert.AreEqual(cmds[2], "/");
            Assert.AreEqual(cmds[3], " ");
            Assert.AreEqual(cmds[4], "two");
        }

        [Test]
        public void Condition()
        {
            var cmd = "tool.rad==0.25?0.05:0";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "tool.rad");
            Assert.AreEqual(cmds[1], "==");
            Assert.AreEqual(cmds[2], "0.25");
            Assert.AreEqual(cmds[3], "?");
            Assert.AreEqual(cmds[4], "0.05");
            Assert.AreEqual(cmds[5], ":");
            Assert.AreEqual(cmds[6], "0");
        }

        [Test]
        public void Parentheses()
        {
            var cmd = "(one+two)/three";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "(");
            Assert.AreEqual(cmds[1], "one");
            Assert.AreEqual(cmds[2], "+");
            Assert.AreEqual(cmds[3], "two");
            Assert.AreEqual(cmds[4], ")");
            Assert.AreEqual(cmds[5], "/");
            Assert.AreEqual(cmds[6], "three");
        }

        [Test]
        public void StringWithParameter()
        {
            var cmd = "Fase &(cham_dp_flat)&mm x 45°";
            var cmds = Parser.StaticScan(cmd);

            Assert.AreEqual(cmds[0], "Fase");
            Assert.AreEqual(cmds[1], " ");
            Assert.AreEqual(cmds[2], "&");
            Assert.AreEqual(cmds[3], "(");
            Assert.AreEqual(cmds[4], "cham_dp_flat");
            Assert.AreEqual(cmds[5], ")");
            Assert.AreEqual(cmds[6], "&");
            Assert.AreEqual(cmds[7], "mm");
            Assert.AreEqual(cmds[8], " ");
            Assert.AreEqual(cmds[9], "x");
            Assert.AreEqual(cmds[10], " ");
            Assert.AreEqual(cmds[11], "45°");
        }
    }
}
